package com.efast.dmom.mgmt.service.mes.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.mgmt.dao.mes.PmVehicleSeriesAndModelDao;
import com.efast.dmom.mgmt.entity.mes.PmVehicleSeriesAndModel;
import com.efast.dmom.mgmt.service.mes.PmVehicleSeriesAndModelService;

@Service
public class PmVehicleSeriesAndModelServiceImpl implements PmVehicleSeriesAndModelService {
	
	@Autowired
	private PmVehicleSeriesAndModelDao vehicleSeriesAndModelDao ;

	@Override
	public ResultBean saveVehicleSeries(PmVehicleSeriesAndModel enti) {
		ResultBean result = new ResultBean(true, "'");
		result.setSuccess(true);
		List<PmVehicleSeriesAndModel> listVehicleSeries = vehicleSeriesAndModelDao.selectVehicleSeriesByName(enti.getVehicleSeriesName());
		if(listVehicleSeries.size()>0) {
			result.setSuccess(false);
			result.setMessage("该车系信息已经存在！");
			return result;
		}
		enti.setCreateTime(new Date());
		enti.setCreateUser(SpringWebUtils.getRequestUser());
		enti.setCompanyCode(SpringWebUtils.getRequestCompany());
		vehicleSeriesAndModelDao.saveVehicleSeries(enti);
		return result;
	}
	@Override
	public ResultBean saveVehicleModel(PmVehicleSeriesAndModel enti) {
		ResultBean result = new ResultBean(true, "'");
		result.setSuccess(true);
		List<PmVehicleSeriesAndModel> listVehicleModel = vehicleSeriesAndModelDao.selectVehicleModelByName(enti.getVehicleModelName());
		if(listVehicleModel.size()>0) {
			result.setSuccess(false);
			result.setMessage("该车型信息已经存在！");
			return result;			
		}
		enti.setCreateTime(new Date());
		enti.setCreateUser(SpringWebUtils.getRequestUser());
		enti.setCompanyCode(SpringWebUtils.getRequestCompany());
		vehicleSeriesAndModelDao.saveVehicleModel(enti);
		return result;
	}

	@Override
	public void deleteVehicleSeriesById(Integer id) {
		vehicleSeriesAndModelDao.deleteVehicleModelBySeriesId(id);
		vehicleSeriesAndModelDao.deleteVehicleSeriesById(id);
	}

	@Override
	public void deleteVehicleModelById(Integer id) {
		vehicleSeriesAndModelDao.deleteVehicleModelById(id);
		
	}


}
